import java.util.*;
/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 09 - 26
 * Time: 21:32
 */
//牛客 连续子数组的最大和
public class Solution8 {
    public int FindGreatestSumOfSubArray (int[] array) {
        int i = 0;
        int max = array[0];
        int[] dp = new int[array.length];
        dp[0] = array[0];
        for (i = 1; i < array.length; i++) {
            dp[i] = getMax(dp[i - 1] + array[i], array[i]);
            if(dp[i] > max) {
                max = dp[i];
            }
        }
        return max;
    }
    private int getMax(int a, int b) {
        return a > b ? a : b;
    }
}
